﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace RoadSign
{
    public partial class MyPictureBox : UserControl
    {
        private Form1 form;
        private string filename;
        //穿入form响应点击，穿入bitmap初始化picturebox,穿入文件路径以打开相应文件
        public MyPictureBox(Form1 form,Bitmap bitmap,string filename)
        {
            InitializeComponent();
            this.form = form;
            this.Width = 100;
            this.Height = 100;
            this.pictureBox1.Width = 100;
            this.pictureBox1.Height = 100;
            this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            this.pictureBox1.Image = bitmap;
            this.filename = filename;
            this.Cursor = Cursors.Hand;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.form.show(this.filename);
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (File.Exists(this.filename))
            {
                File.Delete(this.filename);
            }
            this.form.getPanel().Controls.Remove(this);
            this.Dispose();
        }
    }
}
